package com.ftw.commons.language

import android.content.Context
import java.util.*
import android.content.SharedPreferences



/**
 * 描    述：
 * 作    者：fantianwen
 * 时    间：2019-06-19  18:45
 */

class LocalUtils(context: Context) {

    private val NAME = "language_setting"
    private val LANGUAGE_SELECT = "language_select"

    private val mSharedPreferences: SharedPreferences

    var systemCurrentLocal = Locale.ENGLISH!!

    val selectLanguage: Int
        get() = mSharedPreferences.getInt(LANGUAGE_SELECT, 0)


    init {
        mSharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE)
    }


    fun saveLanguage(select: Int) {
        val edit = mSharedPreferences.edit()
        edit.putInt(LANGUAGE_SELECT, select)
        edit.apply()
    }

    companion object {

        @Volatile
        private var instance: LocalUtils? = null

        fun getInstance(context: Context): LocalUtils? {
            if (instance == null) {
                synchronized(LocalUtils::class.java) {
                    if (instance == null) {
                        instance =
                            LocalUtils(context)
                    }
                }
            }
            return instance
        }
    }
}